home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / sphigs / sph_dos.lha / dos / sphdemo / main.c next >
Encoding:
C/C++ Source or Header  |  1991-11-26  |  8.4 KB  |  347 lines

  1. /* main.c */
  2.  
  3. #include "SPHDEMO.h"
  4. #include "struct.h"
  5. #include "view.h"
  6.  
  7. /** NOTE TO READER
  8. This program was originally written on the Mac and included dialog boxes
  9. and help windows that taught the concepts of viewing.  That's why there
  10. are stubs and unused variables in this main module, which used to handle
  11. all the Mac-specific user interface widgets.
  12. **/
  13.  
  14.  
  15. static int currenderitem = 4, curchimneymenuitem = 'c';
  16. static int curgridmenuitem = 1, curvpmenuitem = 'A';
  17. static int curCamDialogID = 0;
  18.  
  19. static int curHelpDialogID = 0;
  20.  
  21.  
  22. #define rendermenuID   200
  23. #define cameramenuID   202
  24. #define chimneymenuID  201
  25. #define viewportmenuID 204
  26. #define pickmenuID     205
  27. #define gridmenuID     203
  28. #define modelmenuID    206
  29. #define applemenuID    209
  30.  
  31.  
  32.  
  33. static void InstallCameraDialog (int whichitem)
  34. {
  35.    curCamDialogID = whichitem + 300;
  36.    switch (whichitem) {
  37.     case 1:
  38.       fprintf (stderr, "You are now controlling the VRP along the UVN axes...\n");
  39.       break;
  40.     case 2:
  41.       fprintf (stderr, "You are now controlling the VRP along the XYZ axes...\n");
  42.       break;
  43.     case 3:
  44.       fprintf (stderr, "You are now controlling the VPN...\n\
  45.       You can 'yaw' (rotate about the V axis) by using the S and D keys\n\
  46.       You can 'pitch' (rotate about the U axis) by using the E and X keys\n");
  47.       break;
  48.     case 4:
  49.       fprintf (stderr, "You are now controlling the PRP...\n\
  50.       Move it towards the viewplane (reduce the focal length) using - key\n\
  51.       Move it away from the viewplane (increase focal length) using = key\n");
  52.       break;
  53.     case 5:
  54.       fprintf (stderr, "You are now controlling the Front clipping plane\n\
  55.       Use = to bring it towards eye, - to push away from eye\n");
  56.       break;
  57.     case 6:
  58.       fprintf (stderr, "You are now controlling the Back clipping plane\n\
  59.       Use = to bring it towards eye, - to push away from eye\n");
  60.       break;
  61.    }
  62. }
  63.  
  64. static void InstallHelpDialog (int whichmenuid)
  65. {
  66. }
  67.  
  68.  
  69. static int motion_granularity = 30;
  70.  
  71. static void DisplayMotionGranularity (void)
  72. {
  73.    fprintf (stderr,  "Current motion granularity is %d\n", motion_granularity);
  74. }
  75.  
  76.  
  77.  
  78. static void AddGridInFrontOfRoot (int structID, int viewID)
  79. {
  80.    SPH_unpostRoot (structID, viewID);
  81.    SPH_postRoot (GRID_STRUCT, viewID);
  82.    SPH_postRoot (structID, viewID);
  83. }
  84.  
  85.  
  86.  
  87.  
  88. static void ChangeCameraOnAxis (int axis, double bias)
  89. {
  90.    double pitch=0.0, yaw=0.0;
  91.    switch (curCamDialogID) {
  92.     case 301:
  93.       ChangeVRP_relativeUVN (bias*motion_granularity, axis);
  94.       break;
  95.     case 302:
  96.       ChangeVRP_relativeWC (bias*motion_granularity, axis);
  97.       break;
  98.     case 303:
  99.       switch (axis) {
  100.        case X_AXIS:
  101.      yaw = bias * motion_granularity; break;
  102.        case Y_AXIS:
  103.      pitch = bias * motion_granularity; break;
  104.        default:
  105.      return;
  106.       }
  107.       ChangeVPN (pitch, yaw);
  108.       break;
  109.     case 304:
  110.       if (axis != Z_AXIS)
  111.      return;
  112.       ChangePRP (bias*motion_granularity);
  113.       break;
  114.     case 305:
  115.       if (axis != Z_AXIS)
  116.      return;
  117.       ChangeFrontClipPlane (bias*motion_granularity);
  118.       break;
  119.     case 306:
  120.       if (axis != Z_AXIS)
  121.      return;
  122.       ChangeBackClipPlane (bias*motion_granularity);
  123.       break;
  124.    }
  125.    ShowUsingNewView1 ();
  126. }
  127.  
  128.  
  129.  
  130. static void PrintCorrelationInfo (pickInformation *pinfo)
  131. {
  132.    if (pinfo->pickLevel == 4)
  133.       printf ("You picked the chimney on ");
  134.    else
  135.       printf ("You picked ");
  136.  
  137.    printf ("house #%d ", 1 + (int)((pinfo->path[1].elementIndex-1)/3));
  138.  
  139.    printf ("on street #%d.\n", 1 + (int)(pinfo->path[0].elementIndex/2));
  140. }
  141.  
  142.  
  143.  
  144. main (argc, argv)
  145. int argc;
  146. char **argv;
  147. {
  148.    double bias;
  149.    long result;
  150.    int whichmenu, whichitem, keycode;
  151.    int numplanes=7, numshades=10;
  152.    FILE *debugfile;
  153.    char buffer[100];
  154.    boolean READ_FROM_STDIN = FALSE;
  155.    locator_measure locmeas;
  156.    pickInformation pickinfo;
  157.  
  158.  
  159.    READ_FROM_STDIN = FALSE;
  160.  
  161.    /* STARTUP SPHIGS */
  162.    if (READ_FROM_STDIN) {
  163.       printf ("\nPlease enter number of framebuffer planes to allocate:\n");
  164.       scanf ("%d", &numplanes);
  165.       printf ("\nPlease enter number of shades per flexicolor:\n");
  166.       printf
  167.      ("   (Note: this affects how many different flexicolors will be ");
  168.       printf ("available.)\n");
  169.       scanf ("%d", &numshades);
  170.    }
  171.  
  172.    SPH_begin (640, 480, numplanes, numshades);
  173.  
  174.    printf ("\nThis is what I was able to provide re: colors...\n");
  175.    printf ("     Number of custom, flexible colors: %d\n", NUM_OF_FLEXICOLORS);
  176.    printf ("     Number of custom, non-flexible colors: %d\n\n",
  177.        (NUM_OF_APPL_SETTABLE_COLORS-NUM_OF_FLEXICOLORS));
  178.  
  179.    SPH_setImplicitRegenerationMode (SUPPRESSED);
  180.  
  181.    /* We hope there are enough flexicolors for these. */
  182.    SPH_loadCommonColor (2, "yellow");
  183.    SPH_loadCommonColor (3, "green");
  184.    SPH_loadCommonColor (4, "turquoise");
  185.    SPH_loadCommonColor (5, "pink");
  186.    SPH_loadCommonColor (6, "goldenrod");
  187.    SPH_loadCommonColor (7, "firebrick");
  188.  
  189.    /* But these need not be flexicolors. */
  190.    SPH_loadCommonColor (red, "red");
  191.    SPH_loadCommonColor (grey, "lightgrey");
  192.    SPH_loadCommonColor (orange, "orange");
  193.    SPH_loadCommonColor (yellow, "yellow");
  194.    SPH_loadCommonColor (limegreen, "yellowgreen");
  195.    SPH_loadCommonColor (forestgreen, "forestgreen");
  196.    SPH_loadCommonColor (blue, "blue");
  197.  
  198.    InitAllViews();
  199.    BuildEverything ();
  200.  
  201.    DisplayAllViews ();
  202.    ShowUsingNewView1();
  203.    SPH_postRoot (NEIGHBORHOOD_STRUCT, PERSPECTIVE_VIEW);
  204.  
  205.  
  206.    /* INITIALIZE THE GRANULARITY DIALOG BOX */
  207.    DisplayMotionGranularity();
  208.  
  209.    InstallCameraDialog (2);
  210.  
  211.    SRGP_setKeyboardProcessingMode (RAW);
  212.    SRGP_setInputMode (KEYBOARD, EVENT);
  213.    SRGP_setInputMode (LOCATOR, EVENT);
  214.  
  215.  top:
  216.    SPH_setImplicitRegenerationMode (ALLOWED);
  217.  
  218.    if (READ_FROM_STDIN)
  219.       gets(buffer);
  220.    else {
  221.       switch (SRGP_waitEvent (INDEFINITE)) {
  222.        case KEYBOARD:
  223.      SRGP_getKeyboard (buffer, 2);
  224.      break;
  225.        case LOCATOR:
  226.      SPH_getLocator (&locmeas);
  227.      if (locmeas.button_chord[0] == DOWN)
  228.         if (locmeas.view_index == PERSPECTIVE_VIEW) {
  229.            SPH_pickCorrelate
  230.           (locmeas.position, locmeas.view_index, &pickinfo);
  231.            if (pickinfo.pickLevel > 0)
  232.           PrintCorrelationInfo (&pickinfo);
  233.         }
  234.      goto top;
  235.       }
  236.    }
  237.  
  238.    SPH_setImplicitRegenerationMode (SUPPRESSED);
  239.  
  240.    bias = 1.0;
  241.  
  242.    switch (buffer[0]) {
  243.  
  244.      case '<':
  245.        if ((motion_granularity -= 5) < 1)  motion_granularity =  1;
  246.        DisplayMotionGranularity();
  247.        break;
  248.  
  249.      case '>':
  250.        if ((motion_granularity += 5) > 99) motion_granularity = 99;
  251.        DisplayMotionGranularity();
  252.        break;
  253.  
  254.      case 'g':
  255.        sscanf (buffer, "g%d", &motion_granularity);
  256.        DisplayMotionGranularity();
  257.        break;
  258.  
  259.      case '0':
  260.        RestoreCameraToDefault ();
  261.        ShowUsingNewView1 ();
  262.        break;
  263.  
  264.      case '1':
  265.      case '2':
  266.      case '3':
  267.      case '4':
  268.      case '5':
  269.      case '6':
  270.        InstallCameraDialog (buffer[0] - '0');
  271.        break;
  272.  
  273.      case 's':
  274.        bias = -1.0; /*nobreak*/
  275.      case 'd':
  276.        ChangeCameraOnAxis (X_AXIS, bias);
  277.        break;
  278.  
  279.      case 'x':
  280.        bias = -1.0; /*nobreak*/
  281.      case 'e':
  282.        ChangeCameraOnAxis (Y_AXIS, bias);
  283.        break;
  284.  
  285.      case '-':
  286.        bias = -1.0; /*nobreak*/
  287.      case '=':
  288.        ChangeCameraOnAxis (Z_AXIS, bias);
  289.        break;
  290.  
  291.      case 'C':
  292.      case 'c':
  293.        if (buffer[0] == curchimneymenuitem)
  294.       break;
  295.        if (buffer[0] == 'C') {
  296.       AddChimneyToHouse (HOUSE_STRUCT);
  297.       AddChimneyToHouse (FAKE_HOUSE_TOP_STRUCT);
  298.       AddChimneyToHouse (FAKE_HOUSE_SIDE_STRUCT);
  299.        }
  300.        else {
  301.       TakeChimneyFromHouse (HOUSE_STRUCT);
  302.       TakeChimneyFromHouse (FAKE_HOUSE_TOP_STRUCT);
  303.       TakeChimneyFromHouse (FAKE_HOUSE_SIDE_STRUCT);
  304.        }
  305.        curchimneymenuitem = buffer[0];
  306.        break;
  307.  
  308.      case 'a':
  309.      case 'A':
  310.        if (buffer[0] == curvpmenuitem)
  311.       break;
  312.        SPH_setImplicitRegenerationMode (SUPPRESSED);
  313.        if (buffer[0] == 'a')
  314.       DisplayOnlyFullRenderView();
  315.        else
  316.       DisplayAllViews();
  317.        ShowUsingNewView1();
  318.        SPH_setImplicitRegenerationMode (ALLOWED);
  319.        curvpmenuitem = buffer[0];
  320.        break;
  321.  
  322.      case 'n':
  323.      case 'N':
  324.        SPH_setRenderingMode (PERSPECTIVE_VIEW, LIT_FLAT); break;
  325.  
  326.      case 'm':
  327.      case 'M':
  328.        SPH_setRenderingMode (PERSPECTIVE_VIEW, WIREFRAME); break;
  329.  
  330.      case '}':
  331.        /* Undocumented */
  332.        ChangePRPforOrtho();
  333.        ShowUsingNewView1 ();
  334.        break;
  335.      case '{':
  336.        /* Undocumented */
  337.        ChangePRPforClosestPerspective();
  338.        ShowUsingNewView1 ();
  339.        break;
  340.      case 'q':   /* added option to exit the program 8/24/91 ADR */
  341.      case 'Q':
  342.        SPH_end();
  343.        break;
  344.     }
  345.    goto top;
  346. }
  347.